package com.acane.instagram.controller;

import com.acane.instagram.pojo.Collection;
import com.acane.instagram.pojo.Result;
import com.acane.instagram.service.CollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/collection")
public class CollectionController {

    @Autowired
    private CollectionService collectionService;

    @GetMapping("/get/list")
    public Result getCollectionList(@RequestParam String userId) {
        return collectionService.getCollectionList(userId);
    }

    @GetMapping("/judge/collected")
    public Result judgeCollected(@RequestParam String userId, @RequestParam String postId) {
        return collectionService.judgeCollected(userId, postId);
    }

    @PostMapping("/add")
    public Result addCollection(@RequestParam String userId, @RequestParam String postId) {
        Collection collection = new Collection();
        collection.setUserId(userId);
        collection.setPostId(postId);
        return Result.success(collectionService.save(collection));
    }

    @PostMapping("/cancel")
    public Result cancelCollection(@RequestParam String userId, @RequestParam String postId) {
        return collectionService.cancelCollection(userId, postId);
    }
}
